using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Drawing;
using Athena.Objects;
using Athena.Core;
using System.ComponentModel;

namespace Athena
{
    [Serializable(), Browsable(true), Category("Model"), ReadOnly(false)]
    public class ModelBackground
    {
        public ModelBackground(Color oStart, Color oEnd, BackGroundType oType)
        {
            _oStartColor = oStart;
            _oEndColor = oEnd;
            _oType = oType;
        }
        public ModelBackground()
        {
            _oType = BackGroundType.SolidBackground;
            _oStartColor = Color.White;
        }
        private Color _oStartColor;

        public Color StartColor
        {
            get { return _oStartColor; }
            set { _oStartColor = value; }
        }

        private Color _oEndColor;

        public Color EndColor
        {
            get { return _oEndColor; }
            set { _oEndColor = value; }
        }

        public enum BackGroundType
        {
            SolidBackground,
            LinearGradient,
            RadialGradient,
            RoundedRectangleGradient
        }

        private BackGroundType _oType;

        public BackGroundType Type
        {
            get { return _oType; }
            set { _oType = value; }
        }

        public void Draw(Graphics g, RectangleF oRect)
        {
            switch (Type)
            {
                case BackGroundType.LinearGradient:
                    {
                        System.Drawing.Drawing2D.LinearGradientBrush oBrush = new System.Drawing.Drawing2D.LinearGradientBrush(
                            oRect.Location, new PointF(oRect.Right, oRect.Bottom), _oStartColor, _oEndColor);
                        g.FillRectangle(oBrush, oRect);
                    }
                    break;
                case BackGroundType.RadialGradient:
                    {
                        System.Drawing.Drawing2D.GraphicsPath oPath = new System.Drawing.Drawing2D.GraphicsPath();
                        oPath.AddEllipse(oRect);
                        System.Drawing.Drawing2D.PathGradientBrush oBrush = new System.Drawing.Drawing2D.PathGradientBrush(oPath);
                        oBrush.CenterColor = _oEndColor;
                        oBrush.SurroundColors = new Color[] { _oStartColor };
                        g.FillRectangle(oBrush, oRect);
                    }
                    break;
                case BackGroundType.SolidBackground:
                    g.Clear(_oStartColor);
                    break;
                case BackGroundType.RoundedRectangleGradient:
                    {
                        System.Drawing.Drawing2D.GraphicsPath oPath = new System.Drawing.Drawing2D.GraphicsPath();
                        Utility.GenerateRoundedRectangle(oPath, oRect);
                        System.Drawing.Drawing2D.PathGradientBrush oBrush = new System.Drawing.Drawing2D.PathGradientBrush(oPath);
                        oBrush.CenterColor = _oEndColor;
                        oBrush.SurroundColors = new Color[] { _oStartColor };
                        g.FillRectangle(oBrush, oRect);
                    }
                    break;
            }
        }

    }
}
